/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.bitzer.google;

import com.google.gdata.client.photos.PicasawebService;
import com.google.gdata.data.photos.AlbumEntry;
import com.google.gdata.data.photos.PhotoEntry;
import com.google.gdata.util.AuthenticationException;
import java.util.List;

 
/**
 *
 * @author fstech
 */

    public class Picassa {

    private static Picassa _instance  =   null;
    private static PicasawebService service ;
    private static PicassaWeb picasaWeb  = null;
    public int recordCount         = 0;

    public static Picassa instance(){
        if(_instance == null){
            _instance = new Picassa();
        }
        return _instance;
    }

    public Picassa(){
         
            service = new PicasawebService(Constants.APPLICATION_NAME);
        
    }

    public void authenticate(String username, String password) throws AuthenticationException {

        if (username == null || password == null) {
            return;
        }
         picasaWeb =  new PicassaWeb(service, username, password);
    }

    public List<AlbumEntry> getFeed(String lastModifiedOn, int startIndex, int numberOfRows) {

         
         List<AlbumEntry> albums = null;
         try {
            
            albums = picasaWeb.fetchAlbums();
            recordCount = albums.size();

            return albums;
        } catch (Exception e) {
            return null;
        }
    }

    public List<PhotoEntry> getPhotosFeed(String lastModifiedOn, int startIndex, int numberOfRows , String albumId){

        List<AlbumEntry> albums = null;
        try {

            albums = picasaWeb.fetchAlbums();
            
        } catch (Exception e) {
            return null;
        }
        try {

            List<PhotoEntry> photos     =   picasaWeb.getAlbumPhotos(albums, albumId);
            recordCount = photos.size();
            return photos;

        } catch (Exception ex) {
            return null;
        }
    }
    
    public static void main(String args[]) throws AuthenticationException{

    }
   
}
